package com.lboyang.provider.registry.nacos.util;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.lboyang.common.enums.RpcErrorMessageEnum;
import com.lboyang.common.exception.RpcException;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description
 * @Date 2021/9/12 20:22
 * @author: A.iguodala
 */
@Slf4j
public class NamingServiceUtil {

    /**
     * 默认地址
     */
    private static final String DEFAULT_NACOS_ADDRESS = "127.0.0.1:8848";

    /**
     * nacos 服务工具类
     */
    public static final NamingService namingService;

    static {
        try {
            namingService = NamingFactory.createNamingService(DEFAULT_NACOS_ADDRESS);
        } catch (NacosException e) {
            log.error("connet to nacos fail: {}", e);
            throw new RpcException(RpcErrorMessageEnum.CLIENT_CONNECT_SERVER_FAILURE);
        }
    }

}
